package org.example.myportfolio.controller;


import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import lombok.extern.slf4j.Slf4j;
import org.example.myportfolio.config.response.JsonResult;
import org.example.myportfolio.pojo.param.LoginParam;
import org.example.myportfolio.pojo.vo.UserVO;
import org.example.myportfolio.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Validated
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 用户登录
     * @param loginParam
     * @return
     */
    @PostMapping("login")
    public JsonResult login(@Validated @RequestBody LoginParam loginParam) {
        log.info("用户登录入参：{}",loginParam.getName());
        if(ObjectUtils.isEmpty(loginParam)){//判断传参对象是否为空
            log.error("对象为空！");
            return JsonResult.fail("登录失败！");
        }
        JsonResult login = userService.login(loginParam);
        return JsonResult.ok(login);

    }



}
